//
//  EnterViewController.m
//  ZiJinLian
//
//  Created by 🐛 on 2017/4/14.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "EnterViewController.h"
#import "InformationTableViewCell.h"
@interface EnterViewController ()<UITableViewDelegate,UITableViewDataSource>


@property (nonatomic, strong) UITableView    * tableView;
@property (nonatomic, strong) NSArray        * array;
@property (nonatomic , strong)NSMutableArray *arrayDataSouce;
@end

@implementation EnterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.array=[NSArray arrayWithObjects:MyString(@"姓名"),MyString(@"联系电话"),MyString(@"身份证号"), nil];
    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, MainW, 200) style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.backgroundColor=Gray_Color;
    tableView.dataSource = self;
    tableView.scrollEnabled =NO;
    tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    tableView.separatorColor=SeparatorColor;
    tableView.separatorInset=UIEdgeInsetsZero;
    [self.view addSubview:tableView];
    self.tableView = tableView;
    [tableView registerNib:[UINib nibWithNibName:@"InformationTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"InformationTableViewCell"];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldDidChanged:) name:UITextFieldTextDidChangeNotification object:nil];
    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(10, 230, MainW-20, 50)];
    [btn setTitle:@"确定" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setBackgroundColor:Red_Color];
    [btn addTarget:self action:@selector(showBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    ViewRadius(btn, 5);
}
-(void)showBtnClick{
    [self.view endEditing:YES];
    [self.arrayDataSouce enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString *string = (NSString *)obj;
        if (string.length == 0) {
            NSLog(@"第%lu个位置元素为空", (unsigned long)idx);
        }else{
            NSLog(@"%@", obj);
        }
    }];
    NSLog(@"填写的数据%@",self.arrayDataSouce);
}
- (void)textFieldDidChanged:(NSNotification *)noti{
    /// 数据源赋值
    UITextField *textField=noti.object;
    [self.arrayDataSouce replaceObjectAtIndex:textField.tag withObject:textField.text];
}
- (NSMutableArray *)arrayDataSouce{
    if (!_arrayDataSouce) {
        _arrayDataSouce = [NSMutableArray array];
        [_arrayDataSouce addObject:@""];
        [_arrayDataSouce addObject:@""];
        [_arrayDataSouce addObject:@""];
        
    }
    return _arrayDataSouce;
}
#pragma mark -------- tableviewdelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    InformationTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"InformationTableViewCell"];
        if (!cell) {
            cell = [tableView dequeueReusableCellWithIdentifier:@"InformationTableViewCell"];
        }
        cell.textField.tag=indexPath.row;
        cell.titleName.text=self.array[indexPath.row];
        return cell;
    
    
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
        UIView *view=[[UIView alloc]init];
        view.backgroundColor=Gray_Color;
        MYLabel*label=[[MYLabel alloc]initWithFrame:CGRectMake(10, 15, MainW-10, 20)];
        label.text=@"个人信息";
        label.backgroundColor=[UIColor clearColor];
        label.textColor=TextColor3;
        [view addSubview:label];
        return view;
}

@end
